// 测试题目格式化逻辑
function formatQuestionsForAPI(questions, questionType, difficultyLevel) {
    if (!Array.isArray(questions)) {
        console.error('题目数据格式错误，应为数组:', questions);
        return [];
    }

    return questions.map(question => {
        // 映射题目类型: choice → choose, TF → judge
        const typeMapping = {
            'choice': 'choose',
            'TF': 'judge',
            'fill': 'fill',
            'answer': 'answer'
        };

        // 映射难度级别: easy → "1", difficulty → "2"
        const levelMapping = {
            'easy': '1',
            'difficulty': '2'
        };

        const mappedType = typeMapping[questionType] || questionType;
        const mappedLevel = levelMapping[difficultyLevel] || difficultyLevel;

        return {
            quType: mappedType,
            level: mappedLevel,
            content: question
        };
    });
}

// 测试数据
const testQuestions = [
    {
        "answer": "A. 单位脉冲函数",
        "choose": [
            "A. 单位脉冲函数",
            "B. 矩形脉冲函数",
            "C. 高斯脉冲函数",
            "D. 振荡脉冲函数"
        ],
        "point": "δ函数的定义",
        "question": "δ函数又称为什么？"
    }
];

// 测试单选题
console.log('=== 测试单选题格式化 ===');
const choiceResult = formatQuestionsForAPI(testQuestions, 'choice', 'easy');
console.log(JSON.stringify(choiceResult, null, 2));

// 测试判断题
console.log('\n=== 测试判断题格式化 ===');
const tfResult = formatQuestionsForAPI(testQuestions, 'TF', 'difficulty');
console.log(JSON.stringify(tfResult, null, 2));

console.log('\n=== 测试完成 ===');
